<?php
/**
 * Created by jinqiang on 2024/9/24 14:27.
 * Copyright (c) 2024, Your Company. All rights reserved.
 */


namespace App\Http\Controllers\Soa;


use App\Http\Controllers\Controller;
use App\Http\Services\Soa\ContractService;
use Illuminate\Http\Request;

class ContractController extends Controller
{
    //成衣合同列表
    public function list(Request $request, ContractService $contractService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $contractService->search($param);
        return result($res);
    }

    //绣花合同列表
    public function listXh(Request $request, ContractService $contractService)
    {
        $this->validate($request, [
            'page' => 'required',
            'limit' => 'required'
        ]);
        $param = $request->all();
        $res = $contractService->searchXh($param);
        return result($res);
    }

    //重发签署
    public function pushSignature(Request $request, ContractService $contractService)
    {
        $this->validate($request, [
            'id' => 'required'
        ]);
        $param = $request->all();
        $res = $contractService->pushSignature((Int)$param['id']);
        return $res['code'] === 0 ? success("操作成功") : error($res['msg'], $res);
    }

    //合同审核进度
    public function approvalProcess(Request $request, ContractService $contractService)
    {
        $this->validate($request, [
            'id' => 'required',
            'run_id' => 'required'
        ]);
        $param = $request->all();
        $res = $contractService->approvalProcess($param);
        return result($res);
    }

    //获取合同附件
    public function signUrl(Request $request, ContractService $contractService)
    {
        $this->validate($request, [
            'id' => 'required'
        ]);
        $param = $request->all();
        $res = $contractService->signUrl((Int)$param['id']);
        return $res['code'] === 0 ? success("操作成功", $res['data']) : error($res['msg'], $res);
    }

    //作废合同
    public function cancel(Request $request, ContractService $contractService)
    {
        $this->validate($request, [
            'id' => 'required'
        ]);
        $param = $request->all();
        $res = $contractService->cancel((Int)$param['id']);
        return $res['code'] === 0 ? success("操作成功") : error($res['msg'], $res);
    }

    //提交合同
    public function submit(Request $request, ContractService $contractService)
    {
        $this->validate($request, [
            'id' => 'required'
        ]);
        $param = $request->all();
        $res = $contractService->submit((Int)$param['id']);
        return $res['code'] === 0 ? success("操作成功") : error($res['msg'], $res);
    }
}
